class HomeController < ApplicationController

  before_filter :login_required
    rescue_from Exception, :with => :render_error

  def render_error(exception)
    logger.info "User logged : #{current_user.inspect}"
    log_error(exception)
    render :template => "/errors/error.html.erb"
  end

  def index
    redirect_to(:controller => 'reports', :action => 'index')
  end
  
  def translate
   logger.error "Called translate "
   logger.error IO.popen("whoami").readlines.inspect
   s = IO.popen("sudo #{RAILS_ROOT}/translate.rb 2>&1")
   logger.error s.readlines.inspect
  end
  
  def extract
    var = QuestionByRole.all.map{|q| "_(\""+q.text+"\")\n"}.to_s + QuestionOption.all.map {|o| "_(\""+o.text+"\")\n"}.to_s + Country.all.map{|c| "_(\""+c.name+"\")\n"}.to_s +  Site.all.map{|s| "_(\""+s.name+"\")\n"}.to_s + Strategy.all.map{|st| "_(\""+st.name+"\")\n"}.to_s + Strategy.all.map{|sh| "_(\""+sh.short_name+"\")\n"}.to_s + ReportRequest.all.map{|rr| "_(\""+rr.title+"\")\n"}.to_s
    File.open("po\/mbds_db.rb", 'w') {|f| f.write(var) }
    require 'gettext_rails/tools'
    GetText.update_pofiles("mbds_dynamic", Dir.glob("{po}/**/*.{rb}"), "mbds 1.0.0")
    redirect_to request.referer
  end
end



